using EasyIot.Repository;
using EasyIot.WebApp.Common;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using System.IO;

namespace EasyIot.WebApp
{
    public class Program
    {
        static string WebPort { get; set; }
         
        public static void Main(string[] args)
        { 

            var configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile("appsettings.json").Build(); 
            var appSettings = configuration.GetSection("AppSettings");
            WebPort = appSettings["WebPort"];
            DbContext.ConnectionString = appSettings["ConnectionString"]; 
            DataMgr.ApiUrl = appSettings["ApiUrl"];

            CreateHostBuilder(args).Build().Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseStartup<Startup>().UseUrls($"http://*:{WebPort}");
            });
    }
}
